<template>
  <div class="searchHistory">
    <div class="tabbar">
      <div class="title">搜索历史</div>
      <!-- <div class="del"> -->
        <i class="del icon icon-del"></i>
      <!-- </div> -->
    </div>
    <div class="history" @click="search">
      <div class="tag" :data-name="item" v-for="item,i in history" :key="i">
        {{item}}
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'SearchHistory',
  computed: {
    ...mapState({
      history: (state) => state.user.history
    })
  },
  methods: {
    search (e){
      const name = e.target.dataset.name
      if (name) this.$store.dispatch('searchBook', name)
    }
  }
}
</script>

<style lang="less" scoped>
.searchHistory{
  height: 100px;
  padding: .5em 5%;
  .tabbar{
    margin: .6em auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--font-color);
    .title{
      font-size: 1.5em;
    }
    .del{
      font-size: .7em;
    }
  }
  .history{
    display: flex;
    flex-flow: row wrap;
    .tag{
      color: var(--icon-color);
      padding: .2em .4em;
      margin-right: .5em;
      background-color: var(--main-darken-bg);
    }
  }

}
</style>
